<template>
  <div class="yanyun-login-container">
    <!-- 背景元素 -->
    <div class="background-layer">
      <div class="ink-splash ink-1"></div>
      <div class="ink-splash ink-2"></div>
      <div class="ink-splash ink-3"></div>
    </div>
    
    <!-- 装饰元素 - 左侧 -->
    <div class="decorative-elements-left">
      <div class="scroll-element scroll-left"></div>
      <div class="mountain-pattern"></div>
    </div>
    
    <!-- 装饰元素 - 右侧 -->
    <div class="decorative-elements-right">
      <div class="bamboo-pattern"></div>
      <div class="scroll-element scroll-right"></div>
    </div>
    
    <!-- 主登录区域 -->
    <div class="main-content-wrapper">
      <!-- 左侧信息面板 -->
      <div class="info-panel">
        <div class="panel-decoration">
          <div class="corner corner-top-left"></div>
          <div class="corner corner-top-right"></div>
          <div class="corner corner-bottom-left"></div>
          <div class="corner corner-bottom-right"></div>
        </div>
        <div class="info-content">
          <h2 class="info-title">江湖风云起</h2>
          <p class="info-description">
            五代十国，天下大乱，燕云十六州，英雄辈出。
            你将扮演一位少侠，在这个动荡的时代中，
            书写属于自己的侠义传奇。
          </p>
          <div class="feature-highlights">
            <div class="highlight-item">
              <span class="highlight-icon">🗡️</span>
              <span class="highlight-text">快意恩仇</span>
            </div>
            <div class="highlight-item">
              <span class="highlight-icon">🏞️</span>
              <span class="highlight-text">水墨江湖</span>
            </div>
            <div class="highlight-item">
              <span class="highlight-icon">👥</span>
              <span class="highlight-text">侠骨柔情</span>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 右侧登录卡片 -->
      <div class="login-card">
        <!-- 卡片装饰边框 -->
        <div class="card-border">
          <div class="border-top"></div>
          <div class="border-bottom"></div>
          <div class="border-left"></div>
          <div class="border-right"></div>
        </div>
        
        <!-- 游戏标志和标题 -->
        <div class="game-header">
          <div class="logo-container">
            <div class="logo-emblem"></div>
          </div>
          <h1 class="game-title">燕云十六声</h1>
          <p class="game-subtitle">江湖路远，侠义永存</p>
        </div>
        
        <!-- 登录表单 -->
        <form @submit.prevent="handleLogin" class="login-form">
          <!-- 用户名输入框 -->
          <div class="form-group">
            <label for="username" class="form-label">侠名</label>
            <div class="input-wrapper">
              <span class="input-icon">📜</span>
              <input
                type="text"
                id="username"
                v-model="username"
                placeholder="请输入您的侠名"
                required
                class="form-input"
                autocomplete="username"
              />
            </div>
          </div>
          
          <!-- 密码输入框 -->
          <div class="form-group">
            <div class="label-wrapper">
              <label for="password" class="form-label">令牌</label>
              <a href="#" class="forgot-password" @click.prevent="handleForgotPassword">令牌丢失？</a>
            </div>
            <div class="input-wrapper">
              <span class="input-icon">🔒</span>
              <input
                type="password"
                id="password"
                v-model="password"
                placeholder="请输入您的令牌"
                required
                class="form-input"
                autocomplete="current-password"
              />
            </div>
          </div>
          
          <!-- 错误消息 -->
          <div v-if="errorMessage" class="error-message">
            <span class="error-icon">⚠️</span>
            {{ errorMessage }}
          </div>
          
          <!-- 记住我选项 -->
          <div class="remember-me">
            <input type="checkbox" id="remember" class="remember-checkbox">
            <label for="remember" class="remember-label">铭记此身</label>
          </div>
          
          <!-- 登录按钮 -->
          <button
            type="submit"
            class="login-button"
            :disabled="isLoading"
          >
            <span v-if="isLoading" class="loading-spinner"></span>
            {{ isLoading ? '踏入江湖中...' : '踏入江湖' }}
          </button>
          
          <!-- 分隔线 -->
          <div class="divider">
            <div class="divider-line"></div>
            <span class="divider-text">或</span>
            <div class="divider-line"></div>
          </div>
          
          <!-- 社交登录选项 -->
          <div class="social-login">
            <button type="button" class="social-button qq-btn" @click="handleSocialLogin('qq')">
              <span class="social-icon">🐧</span>
              <span>QQ账号</span>
            </button>
            <button type="button" class="social-button wechat-btn" @click="handleSocialLogin('wechat')">
              <span class="social-icon">💬</span>
              <span>微信账号</span>
            </button>
          </div>
          
          <!-- 注册账号链接 -->
          <div class="register-link">
            <span>初入江湖？</span>
            <a href="#" @click.prevent="handleRegister">拜入山门</a>
          </div>
        </form>
        
        <!-- 页脚信息 -->
        <div class="login-footer">
          <p>© 2024 燕云十六声. 保留所有权利.</p>
          <div class="footer-links">
            <a href="#" @click.prevent="handleTerms">江湖规矩</a>
            <span class="footer-separator">|</span>
            <a href="#" @click.prevent="handlePrivacy">隐秘之事</a>
            <span class="footer-separator">|</span>
            <a href="#" @click.prevent="handleHelp">江湖求助</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import authService from '../services/auth.js';

const router = useRouter();
const username = ref('admin'); // 默认用户名，方便测试
const password = ref('password'); // 默认密码，方便测试
const errorMessage = ref('');
const isLoading = ref(false);

// 如果用户已经登录，直接跳转到主页
if (authService.checkAuth()) {
  router.push('/');
}

// 处理登录逻辑
const handleLogin = async () => {
  errorMessage.value = '';
  isLoading.value = true;
  
  try {
    await authService.login(username.value, password.value);
    // 登录成功后跳转到主页
    router.push('/');
  } catch (error) {
    errorMessage.value = error.message;
    // 添加错误动画效果
    const errorElement = document.querySelector('.error-message');
    if (errorElement) {
      errorElement.classList.add('error-shake');
      setTimeout(() => {
        errorElement.classList.remove('error-shake');
      }, 500);
    }
  } finally {
    isLoading.value = false;
  }
};

// 处理忘记密码
const handleForgotPassword = () => {
  alert('令牌丢失功能正在开发中');
};

// 处理注册账号
const handleRegister = () => {
  alert('拜入山门功能正在开发中');
};

// 处理社交登录
const handleSocialLogin = (provider) => {
  alert(`${provider === 'qq' ? 'QQ' : '微信'} 账号登录功能正在开发中`);
};

// 处理服务条款
const handleTerms = () => {
  alert('江湖规矩页面正在开发中');
};

// 处理隐私政策
const handlePrivacy = () => {
  alert('隐秘之事页面正在开发中');
};

// 处理帮助中心
const handleHelp = () => {
  alert('江湖求助页面正在开发中');
};
</script>

<style scoped>
/* 引入字体样式 */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&display=swap');

/* 全局变量 */
:root {
  --primary-color: #8a1a1a; /* 中国红 */
  --secondary-color: #d4a017; /* 金色 */
  --dark-color: #2c1e1e; /* 深棕色 */
  --light-color: #f7f1e5; /* 米色 */
  --accent-color: #1b6d85; /* 青色 */
}

/* 登录容器 */
.yanyun-login-container {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  background: var(--light-color);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  font-family: 'Noto Serif SC', serif;
  perspective: 1000px;
}

/* 背景层 */
.background-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0.25;
}

.ink-splash {
  position: absolute;
  border-radius: 50%;
  background: var(--dark-color);
  filter: blur(100px);
}

.ink-1 {
  width: 600px;
  height: 600px;
  top: -300px;
  left: -200px;
}

.ink-2 {
  width: 500px;
  height: 500px;
  bottom: -250px;
  right: -150px;
}

.ink-3 {
  width: 400px;
  height: 400px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* 主内容包装器 */
.main-content-wrapper {
  position: relative;
  z-index: 10;
  display: flex;
  gap: 60px;
  align-items: center;
  justify-content: center;
  max-width: 1600px;
  width: 100%;
  animation: fadeIn 0.8s ease-out;
  transform-style: preserve-3d;
}

/* 左侧信息面板 */
.info-panel {
  position: relative;
  background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
  border-radius: 16px;
  padding: 60px;
  width: 100%;
  max-width: 600px;
  color: var(--light-color);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  transform: rotateY(-5deg) translateZ(0);
  transition: transform 0.5s ease;
}

.info-panel:hover {
  transform: rotateY(0) translateZ(10px);
}

/* 面板装饰 */
.panel-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.corner {
  position: absolute;
  width: 30px;
  height: 30px;
  border-style: solid;
  border-width: 2px;
  border-color: var(--light-color);
  opacity: 0.6;
}

.corner-top-left {
  top: 20px;
  left: 20px;
  border-right: none;
  border-bottom: none;
}

.corner-top-right {
  top: 20px;
  right: 20px;
  border-left: none;
  border-bottom: none;
}

.corner-bottom-left {
  bottom: 20px;
  left: 20px;
  border-right: none;
  border-top: none;
}

.corner-bottom-right {
  bottom: 20px;
  right: 20px;
  border-left: none;
  border-top: none;
}

/* 面板内容 */
.info-content {
  position: relative;
  z-index: 1;
}

.info-title {
  font-size: 2.5rem;
  margin-bottom: 20px;
  text-align: center;
  font-weight: 700;
  letter-spacing: 2px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.info-description {
  font-size: 1.1rem;
  line-height: 1.8;
  text-align: center;
  margin-bottom: 30px;
  opacity: 0.95;
}

/* 特色亮点 */
.feature-highlights {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
}

.highlight-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.1);
  padding: 12px 20px;
  border-radius: 30px;
  backdrop-filter: blur(5px);
  transition: all 0.3s ease;
}

.highlight-item:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateX(5px);
}

.highlight-icon {
  font-size: 1.2rem;
}

.highlight-text {
  font-size: 1rem;
  font-weight: 500;
}

/* 右侧登录卡片 */
.login-card {
  position: relative;
  background: var(--light-color);
  border-radius: 16px;
  padding: 50px;
  width: 100%;
  max-width: 550px;
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  transform: rotateY(5deg) translateZ(0);
  transition: transform 0.5s ease;
  overflow: hidden;
}

.login-card:hover {
  transform: rotateY(0) translateZ(10px);
}

/* 卡片边框装饰 */
.card-border {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.border-top, .border-bottom, .border-left, .border-right {
  position: absolute;
  background: linear-gradient(90deg, var(--primary-color), transparent);
  opacity: 0.5;
}

.border-top {
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
}

.border-bottom {
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary-color));
}

.border-left {
  top: 0;
  left: 0;
  width: 2px;
  height: 100%;
  background: linear-gradient(180deg, var(--primary-color), transparent);
}

.border-right {
  top: 0;
  right: 0;
  width: 2px;
  height: 100%;
  background: linear-gradient(180deg, transparent, var(--primary-color));
}

/* 卡片装饰边框 */
.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color), var(--accent-color));
}

/* 游戏头部 */
.game-header {
  text-align: center;
  margin-bottom: 45px;
}

.logo-container {
  width: 120px;
  height: 120px;
  margin: 0 auto 25px;
  position: relative;
}

.logo-emblem {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, var(--secondary-color) 0%, var(--primary-color) 70%);
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(212, 160, 23, 0.5);
}

.logo-emblem::after {
  content: '燕';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  color: white;
  font-weight: 700;
}

.game-title {
  font-size: 42px;
  color: var(--primary-color);
  margin: 0 0 12px 0;
  font-weight: 700;
  letter-spacing: 3px;
}

.game-subtitle {
  font-size: 16px;
  color: var(--dark-color);
  margin: 0;
  font-style: italic;
}

/* 登录表单 */
.login-form {
  width: 100%;
}

.form-group {
  margin-bottom: 25px;
}

.label-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.form-label {
  display: block;
  font-weight: 600;
  color: var(--dark-color);
  font-size: 14px;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.forgot-password {
  color: var(--accent-color);
  font-size: 13px;
  text-decoration: none;
  transition: color 0.3s ease;
}

.forgot-password:hover {
  color: var(--primary-color);
  text-decoration: underline;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: white;
  border: 1px solid var(--secondary-color);
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.input-wrapper:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(138, 26, 26, 0.1);
}

.input-icon {
  padding: 0 12px;
  font-size: 18px;
  color: var(--secondary-color);
}

.form-input {
  flex: 1;
  padding: 14px;
  border: none;
  outline: none;
  font-size: 16px;
  color: var(--dark-color);
  background: transparent;
}

.form-input::placeholder {
  color: #a0a0a0;
}

/* 错误消息 */
.error-message {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary-color);
  font-size: 13px;
  padding: 8px 12px;
  background: rgba(138, 26, 26, 0.1);
  border: 1px solid var(--primary-color);
  border-radius: 6px;
  margin-bottom: 16px;
  animation: error-slide-in 0.3s ease-out;
}

.error-shake {
  animation: error-shake 0.5s ease-in-out;
}

@keyframes error-slide-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes error-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.error-icon {
  font-size: 14px;
}

/* 记住我选项 */
.remember-me {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.remember-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary-color);
}

.remember-label {
  font-size: 14px;
  color: var(--dark-color);
  cursor: pointer;
}

/* 登录按钮 */
.login-button {
  width: 100%;
  padding: 16px 28px;
  background: linear-gradient(135deg, var(--primary-color) 0%, #5d1212 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: 'Noto Serif SC', serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
  letter-spacing: 1px;
}

.login-button::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  transform: rotate(45deg);
  transition: opacity 0.5s ease;
  opacity: 0;
}

.login-button:hover:not(:disabled)::before {
  opacity: 1;
  animation: shine 1.5s ease-in-out;
}

@keyframes shine {
  0% { transform: translateX(-100%) rotate(45deg); }
  100% { transform: translateX(100%) rotate(45deg); }
}

.login-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(138, 26, 26, 0.3);
}

.login-button:active:not(:disabled) {
  transform: translateY(0);
}

.login-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* 加载动画 */
.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 分隔线 */
.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 30px 0;
}

.divider-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--secondary-color), transparent);
}

.divider-text {
  font-size: 14px;
  color: var(--dark-color);
  font-weight: 500;
}

/* 社交登录按钮 */
.social-login {
  display: flex;
  gap: 12px;
  margin-bottom: 30px;
}

.social-button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  border: 1px solid var(--secondary-color);
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  background: white;
  color: var(--dark-color);
  font-family: 'Noto Serif SC', serif;
}

.social-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.social-icon {
  font-size: 16px;
}

/* 注册链接 */
.register-link {
  text-align: center;
  margin-bottom: 24px;
}

.register-link span {
  font-size: 14px;
  color: var(--dark-color);
  opacity: 0.8;
}

.register-link a {
  color: var(--primary-color);
  font-weight: 600;
  text-decoration: none;
  transition: color 0.3s ease;
  margin-left: 4px;
}

.register-link a:hover {
  color: var(--accent-color);
  text-decoration: underline;
}

/* 登录页脚 */
.login-footer {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid var(--secondary-color);
}

.login-footer p {
  font-size: 12px;
  color: var(--dark-color);
  opacity: 0.7;
  margin: 0 0 12px 0;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 8px;
  align-items: center;
}

.footer-links a {
  font-size: 12px;
  color: var(--accent-color);
  text-decoration: none;
  transition: color 0.3s ease;
}

.footer-links a:hover {
  color: var(--primary-color);
  text-decoration: underline;
}

.footer-separator {
  font-size: 12px;
  color: var(--dark-color);
  opacity: 0.5;
}

/* 左侧装饰元素 */
.decorative-elements-left {
  position: absolute;
  left: 5%;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  opacity: 0.6;
  pointer-events: none;
}

/* 右侧装饰元素 */
.decorative-elements-right {
  position: absolute;
  right: 5%;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  opacity: 0.6;
  pointer-events: none;
}

/* 卷轴元素 */
.scroll-element {
  width: 180px;
  height: 350px;
  background: var(--secondary-color);
  border-radius: 10px;
  position: relative;
  opacity: 0.3;
  animation: scrollFloat 8s ease-in-out infinite;
}

.scroll-left {
  transform: rotate(-10deg);
  margin-bottom: 20px;
}

.scroll-right {
  transform: rotate(10deg);
  margin-top: 20px;
}

/* 山脉图案 */
.mountain-pattern {
  width: 200px;
  height: 150px;
  background: linear-gradient(135deg, var(--primary-color), transparent);
  clip-path: polygon(0% 100%, 50% 0%, 100% 100%);
  opacity: 0.3;
  animation: mountainGlow 4s ease-in-out infinite alternate;
}

/* 竹子图案 */
.bamboo-pattern {
  width: 180px;
  height: 300px;
  background: linear-gradient(90deg, transparent, var(--secondary-color), transparent);
  clip-path: polygon(
    30% 0%, 35% 0%, 35% 100%, 30% 100%,
    65% 0%, 70% 0%, 70% 100%, 65% 100%
  );
  opacity: 0.3;
  animation: bambooSway 6s ease-in-out infinite;
}

.scroll-element::before {
  content: '';
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  bottom: 10px;
  background: var(--light-color);
  border-radius: 2px;
}

/* 中国传统图案动画 */
@keyframes scrollFloat {
  0%, 100% { transform: translateY(0) rotate(-10deg); }
  50% { transform: translateY(-20px) rotate(-5deg); }
}

@keyframes mountainGlow {
  0% { opacity: 0.3; transform: scale(1); }
  100% { opacity: 0.4; transform: scale(1.05); }
}

@keyframes bambooSway {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(2deg); }
}

.pattern-1 {
  transform: rotate(45deg);
}

.pattern-2 {
  border-radius: 50%;
}

/* 响应式设计 */
@media (max-width: 1400px) {
  .main-content-wrapper {
    max-width: 1200px;
  }
  
  .info-panel {
    max-width: 500px;
  }
  
  .login-card {
    max-width: 450px;
  }
}

@media (max-width: 1024px) {
  .main-content-wrapper {
    flex-direction: column;
    gap: 30px;
    max-width: 800px;
  }
  
  .info-panel,
  .login-card {
    transform: rotateY(0) translateZ(0);
    max-width: 500px;
  }
  
  .decorative-elements-left,
  .decorative-elements-right {
    display: none;
  }
}

@media (max-width: 768px) {
  .yanyun-login-container {
    padding: 10px;
  }
  
  .info-panel {
    padding: 30px 20px;
    margin: 10px;
  }
  
  .info-title {
    font-size: 2rem;
  }
  
  .info-description {
    font-size: 1rem;
  }
  
  .login-card {
    padding: 30px 20px;
    margin: 10px;
  }
  
  .game-title {
    font-size: 2rem;
  }
  
  .social-login {
    flex-direction: column;
  }
}
</style>